from sqlalchemy import create_engine
import tushare as ts
from baseEngine import  engine
import pymysql
#创建表，保存沪深300的股票代码和名字
# engine = create_engine('mysql+pymysql://tushare:tushare123@localhost/tushare?charset=utf8')
class BaseStock: 
    def createHs300():
        tableName = 'hs300'
        hsResult = ts.get_hs300s()
        # print(hsResult)
        hsResult.to_sql(tableName, engine.getEngine())

    def getHs300():
        db = pymysql.connect("localhost", "tushare", "tushare123", "tushare")
        cursor = db.cursor()
        selsql = "SELECT * FROM hs300"
        cursor.execute(selsql)
        hsResult = cursor.fetchall()
        return hsResult

    def createZz500():
        tableName = 'zz500'
        zzResult = ts.get_zz500s()
        zzResult.to_sql(tableName, engine.getEngine())

    def getZz500():
        db = pymysql.connect("localhost", "tushare", "tushare123", "tushare")
        cursor = db.cursor()
        selsql = "SELECT * FROM zz500"
        cursor.execute(selsql)
        zzResult = cursor.fetchall()
        return zzResult

# BaseStock.createZz500()